<?php

/**
 * Общий класс конфигов. 
 * 
 */

namespace T4;

class Config extends Standard {
	
	static $instances = array();
	
	public static function getInstance($fileName=null) {
		if ( is_null($fileName) )
			$key = 0;
		else
			$key = $fileName;
		if ( !isset(self::$instances[$key]) ) {
			self::$instances[$key] = new self($fileName);
		}
		return self::$instances[$key];
	}
	
	public function __construct($fileName=null) {
		parent::__construct();
		if ( !is_null($fileName) ) {
			$this->loadFile($fileName);
		}		
	}
	
	public function loadFile($fileName) {
		$parser = new YAML\Parser();
		$data = $parser->parseAsArray( file_get_contents($fileName) );
		$this->fromArray($data);
	}
	
}